package com.tech.cloudapp.biz;


import com.tech.cloudapp.consta.CommConst;
import com.tech.cloudapp.db.service.IQuestionCoreService;
import com.tech.cloudapp.util.SpringUtils;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;

import java.util.HashMap;
import java.util.Map;

public class QuestServiceFactory {

	private static QuestServiceFactory factory;
	private static Object lock = new Object();
	public  static final Map<CommConst.SERVICE_CODE_MAPPING, String> map = new HashMap<>();

	static
	{
//		map.put(
//				CommConst.SERVICE_CODE_MAPPING.BOSS_11010001_01,
//				//"com.zhiyun.crawler.boss.service.impl.JobServiceImpl"
//				"com.tech.crawler.boss.service.impl.NewJobInfoServiceImpl"
//		 );


	}

	public IQuestionCoreService createFactory(CommConst.SERVICE_CODE_MAPPING key)
	{

		String beanPaht = "";
		Object o = null;
		try {
			o = Class.forName(map.get(key)).newInstance();
		}catch (Exception e)
		{
			e.printStackTrace();
		}
		AutowireCapableBeanFactory factory = SpringUtils.getAutowireCapableBeanFactory();
		factory.autowireBean(o);
		return (IQuestionCoreService) o;
	}

	public static QuestServiceFactory getInstance()
	{
		synchronized(lock)
		{
			if(factory == null)
			{
				factory = new QuestServiceFactory();
			}

			return factory;
		}
	}

}
